package com.incar.chuxing.repository

import android.arch.lifecycle.LiveData
import android.arch.lifecycle.MutableLiveData
import com.baidu.mapapi.model.LatLng
import com.incar.chuxing.api.ApiObserver
import com.incar.chuxing.api.SchedulersTransform
import com.incar.chuxing.application.MyApplication
import com.incar.chuxing.base.BaseRepository
import com.incar.chuxing.base.BaseResultBean
import com.incar.chuxing.base.Resource
import com.incar.chuxing.bean.UnFinishedOrderBean
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers

object OrderRepository : BaseRepository() {
    @JvmField
    var orderId: String = ""
    @JvmField
    var bookType: Int = 0
    @JvmField
    var rentType: Int = 0
    @JvmField
    var preOrderId: String = ""

    @JvmField
    var carId: String = ""
    @JvmField
    var curPosition: LatLng = LatLng(0.0, 0.0)
    @JvmField
    var overPlusTime: Long = 0 ////寻车的剩余毫秒
    @JvmField
    var totalTime: Long = 0  //寻车的总时间毫秒
    @JvmField
    var cancelCount: String = "0"

    @JvmStatic
    fun getUnfinishedOrder(): LiveData<Resource<UnFinishedOrderBean>> {
        val liveData = MutableLiveData<Resource<UnFinishedOrderBean>>()
        apiService.getExistingTravel(MyApplication.getInstance().requestFieldMap).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiObserver<UnFinishedOrderBean>() {
                    override fun onLoading(disposable: Disposable) {
                        compositeDisposable.add(disposable)
                        liveData.value = Resource.onLoading()
                    }

                    override fun onLoaded(result: BaseResultBean<UnFinishedOrderBean>) {
                        liveData.value = Resource.onLoaded(result)
                    }


                    override fun onLoadError(t: Throwable) {
                        liveData.value = Resource.onLoadError(t)
                    }

                })
        return liveData
    }


    interface GetUnfinishedOrderDone {
        fun onHaveOrder(data: UnFinishedOrderBean)
        fun onNoOrder()
        fun onError(message: String)
    }
}